var canLike=true;
var likeEnable = function()
{
   var btns = $('.likeBtn');
   for(var j=0;j<btns.length;j++)
   {
       if(rawEvents[j].userlikeit=="1")
       $(btns[j]).css('background-image','url(img/likebtn.png)');
       rawEvents[j].interestedNumber = parseInt(rawEvents[j].interestedNumber);
   }
    $('.likeBtn').click(
      function () {
        
        if(canLike == true)
        {
            var i= parseInt($(this).parents('.event').attr('id'));
            var jsonObj = new Object;
            jsonObj.id = rawEvents[i].id;
            jsonObj.user = userID;
            console.log('like pressed');
            console.log(jsonObj);
            httpPost('interested',jsonObj,changeinterestedResponse);
            var add;
            if(rawEvents[i].userlikeit==0)
            {
                $(this).css('background-image','url(img/likebtn.png)');
                rawEvents[i].userlikeit = "1";
                
                add=1;
            }
            else
            {
                $(this).css('background-image','url(img/unpressed_likebtn.png)');
                rawEvents[i].userlikeit = "0";
                add=-1;
            }
          
            $(this).next('.interestedNumber').text((rawEvents[i].interestedNumber+=add)+"人覺得有趣");
        }       
        canLike = false;
      } 
    );
}
var changeinterestedResponse = function (response) {
    console.log(response);
    canLike = true;
}


var eventInterestedInfo= function()
{
    var jsonObj={"id":eventID,"user":userID};
    httpPost('interested',jsonObj,eventInterestedInfoResponse);
    
}
var eventLikeNum;
var userLikeStatus ;

var eventInterestedInfoResponse = function(response)
{
   
    showLikeStatus();
}
var showLikeStatus = function()
{
    $('#likeNum').val(eventLikeNum);
    $('#likeStatus').src
}
